package com.zt.student.controller;

import com.zt.common.pojo.common.JsonResult;
import com.zt.common.pojo.netty.Sender;
import com.zt.student.dto.SelectClassDTO;
import com.zt.student.service.ClassSelectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * description:
 * author:zt
 * date:2022-01-02
 */
@RestController
@CrossOrigin
@RequestMapping("classSelection")
@Api("关联学生与选择的课堂")
public class ClassSelectionController {

    @Autowired
    private ClassSelectionService classSelectionService;

    @PostMapping("insert")
    @ApiOperation("学生选课")
    public JsonResult insert(@RequestBody SelectClassDTO selectClassDTO, HttpServletRequest request){
        classSelectionService.insert(selectClassDTO,request);
        return JsonResult.success();
    }

    @PostMapping("delete")
    @ApiOperation("学生退课")
    public JsonResult delete(@RequestBody SelectClassDTO selectClassDTO, HttpServletRequest request){
        classSelectionService.delete(selectClassDTO,request);
        return JsonResult.success();
    }

    @GetMapping("getTeachers/{semester}")
    @ApiOperation("获取所有上课的老师信息")
    public JsonResult<List<Sender>> getSelectedTeacherInfo(HttpServletRequest request,@PathVariable String semester){
        List<Sender> teacherInfo = classSelectionService.getSelectedTeacherInfo(request,semester);
        return JsonResult.success(teacherInfo);
    }
}
